using Itdavany.Utility;
using Itdavany.Data;
using Itdavany.Data.XmlFormat;
using Itdavany.Objects;

namespace Itdavany.Utility
{
    public class AnimationConverter : DefaultConverter
    {
        public override ObjectType Type
        {
            get
            {
                return ObjectType.Animation;
            }
        }

        public override object Convert(ObjectDescription objDesc, ObjectDescriber objDescriber, WidgetFormat parentformat)
        {
            Animation animation = new Animation();

                animation.Frames = (FrameArray)base.Convert(objDesc, objDescriber, parentformat);

            animation.FrameTags = new System.Collections.Generic.List<Animation.FrameTag>();

            foreach (Frame fdesc in objDesc.Frame)
            {
                Animation.FrameTag frametag = new Animation.FrameTag();
                frametag.delay = System.Convert.ToInt32(fdesc.Delay);

                animation.FrameTags.Add(frametag);
            }
            if (objDesc.Animation != null)
            {
                animation.looping = objDesc.Animation.Looping;
            }
            //animation.looping = 

            return animation;

        }

        public override object Convert(ObjectDescription objDesc, ObjectDescriber objDescriber)
        {

            return Convert(objDesc, objDescriber, null);
            
        }
    }
}